package com.iris.jvmtest.hotspot;

import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

/**
 * @author : Iris.Xiao
 * @date : 2017/10/24 10:56
 * @description :
 */
public class ExecuteClass {

    public byte[] getByte(String filepath) throws IOException {
        FileInputStream fis = new FileInputStream(filepath);
        byte[] b = new byte[fis.available()];
        fis.read(b);
        fis.close();

        return b;
    }

    public void execute(String filepath,String methodName,Object ... params) throws Exception {
        byte[] b = getByte(filepath);
        MyClassLoader myClassLoader = new MyClassLoader();
        Class cls = myClassLoader.loadByte(b);
        Object obj = cls.newInstance();
        Method method = cls.getMethod(methodName,String.class);
        method.invoke(obj,params);
    }


}
